<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
@if ((connections | async)?.length) {
  <ng-container *ngTemplateOutlet="hasConnections"></ng-container>
} @else {
  @if ((isLoading$ | async) === false) {
    <div class="add-connection-container">
      <button class="add-connection-btn flex items-center" (click)="addConnection($event)">
        <mat-icon class="mat-icon tb-mat-64">add</mat-icon>
        <span translate>ws-client.connections.add-connection</span>
      </button>
    </div>
  }
}

<ng-template #hasConnections>
  @if (layoutSingleColumn | async) {
    <ng-container *ngTemplateOutlet="singleColumn"></ng-container>
  } @else {
    <div class="mat-padding flex h-full gap-3">
      <section class="client-container !w-[30%]">
        <section class="client-section">
          <tb-connections></tb-connections>
        </section>
        <section class="client-section auto-flex">
          <tb-ws-subscriptions></tb-ws-subscriptions>
        </section>
        <section class="client-section pr-4 pl-4 flex flex-row gap-4 items-between">
          <tb-help-page [label]="'ws-client.settings'"
                        [page]="'/settings/general'"
                        [icon]="'settings'"
                        [tooltip]="'ws-client.settings-navigate'">
          </tb-help-page>
          <tb-help-page [page]="'https://thingsboard.io/docs/mqtt-broker/user-guide/ui/websocket-client'"></tb-help-page>
        </section>
      </section>
      <section class="client-container !w-[70%]">
        <section class="client-section">
          <tb-connection-controller></tb-connection-controller>
        </section>
        <section class="client-section auto-flex">
          <tb-messanger></tb-messanger>
        </section>
      </section>
    </div>
  }
</ng-template>

<ng-template #singleColumn>
  <section class="mat-padding client-container">
    <section class="client-section">
      <tb-connections></tb-connections>
    </section>
    <section class="client-section">
      <tb-connection-controller></tb-connection-controller>
    </section>
    <section class="client-section">
      <tb-messanger></tb-messanger>
    </section>
    <section class="client-section">
      <tb-ws-subscriptions></tb-ws-subscriptions>
    </section>
    <section class="client-section">
      <tb-help-page [page]="'https://thingsboard.io/docs/mqtt-broker/user-guide/ui/websocket-client'"></tb-help-page>
    </section>
  </section>
</ng-template>

